package com.demo.io;

import java.net.InetAddress;

/**
 * @author : YU.TAN
 * @date : 2021/11/15 14:02
 */
public class TestInetAddress {
    public static void main(String[] args) throws Exception {
        //查询本机的ip地址
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println(localHost);
        InetAddress localhost = InetAddress.getByName("localhost");
        System.out.println(localhost);

        System.out.println("=================");
        //查询网站ip地址
        InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
        System.out.println(inetAddress);
        //常用方法
        System.out.println("=================");
        System.out.println(inetAddress.getHostAddress());//获取主机ip地址
        System.out.println(inetAddress.getHostName());// 获取域名
        System.out.println(inetAddress.getCanonicalHostName());//获取规范的主机ip地址

    }
}
